package org.example.leetcode;

import java.util.List;

/**
 * @version 1.0.0
 * @author: lynn
 * @description:
 * @date: 2021/8/12 9:15
 */
public class LC61 {
    public static void main(String[] args) {
        ListNode listNode=new ListNode(1);
        listNode.next=new ListNode(2);
        listNode.next.next=new ListNode(3);
        listNode.next.next.next=new ListNode(4);
        listNode.next.next.next.next=new ListNode(5);
        LC61 lc=new LC61();
        lc.rotateRight(listNode,8);
        System.out.println("xxxxx");
    }
    public ListNode rotateRight(ListNode head, int k) {
        if (head ==null) return head;
        ListNode dummyNode=head;
        int count=1;//链表长度
        while (dummyNode.next!=null){ //fixme dummyNode!=null,要衔接的话，肯定要让最后的node不能为空
            count++;
            dummyNode=dummyNode.next;
        }
        int tmp=count-k%count;//fixme 循环链表取余数
        dummyNode.next=head;
        while (tmp>0){
            tmp--;
            dummyNode=dummyNode.next;
        }
        head=dummyNode.next;
        dummyNode.next=null;
        return head;
    }
    public static class ListNode{
        int val;
        ListNode next;
        ListNode(){};
        ListNode(int val){
            this.val=val;
        }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }
}
